//package org.example.gradlespringbootadmin.config;
//
//import de.codecentric.boot.admin.server.config.AdminServerProperties;
//import org.example.gradlespringbootadmin.GradleSpringBootAdminApplication;
//import org.springframework.boot.SpringApplication;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.security.config.Customizer;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
//import org.springframework.security.config.http.SessionCreationPolicy;
//import org.springframework.security.config.web.server.ServerHttpSecurity;
//import org.springframework.security.web.SecurityFilterChain;
//import org.springframework.security.web.server.SecurityWebFilterChain;
//import org.springframework.security.web.server.authentication.RedirectServerAuthenticationSuccessHandler;
//import org.springframework.security.web.server.authentication.ServerAuthenticationSuccessHandler;
//import org.springframework.security.web.server.authentication.logout.RedirectServerLogoutSuccessHandler;
//import org.springframework.security.web.server.authentication.logout.ServerLogoutSuccessHandler;
//
//import java.net.URI;
//
///**
// * Spring Boot Admin 安全配置
// * 使用与认证模块相同的安全配置方式
// *
// * @author 1141193930@qq.com
// */
//@Configuration
//public class SecurityConfiguration {
//
//
//    private final AdminServerProperties adminServer;
//
//    public SecurityConfiguration(AdminServerProperties adminServer) {
//        this.adminServer = adminServer;
//    }
//
//
//    @Bean
//    public SecurityWebFilterChain securityWebFilterChainSecure(ServerHttpSecurity http) {
//        return http
//                .authorizeExchange(
//                        (authorizeExchange) -> authorizeExchange.pathMatchers(this.adminServer.path("/assets/**"))
//                                .permitAll()
//                                .pathMatchers("/actuator/health/**")
//                                .permitAll()
//                                .pathMatchers(this.adminServer.path("/login"))
//                                .permitAll()
//                                .anyExchange()
//                                .authenticated())
//                .formLogin((formLogin) -> formLogin.loginPage(this.adminServer.path("/login"))
//                        .authenticationSuccessHandler(loginSuccessHandler(this.adminServer.path("/"))))
//                .logout((logout) -> logout.logoutUrl(this.adminServer.path("/logout"))
//                        .logoutSuccessHandler(logoutSuccessHandler(this.adminServer.path("/login?logout"))))
//                .httpBasic(Customizer.withDefaults())
//                .csrf(ServerHttpSecurity.CsrfSpec::disable)
//                .build();
//    }
//
//    // The following two methods are only required when setting a custom base-path (see
//    // 'basepath' profile in application.yml)
//    private ServerLogoutSuccessHandler logoutSuccessHandler(String uri) {
//        RedirectServerLogoutSuccessHandler successHandler = new RedirectServerLogoutSuccessHandler();
//        successHandler.setLogoutSuccessUrl(URI.create(uri));
//        return successHandler;
//    }
//
//    private ServerAuthenticationSuccessHandler loginSuccessHandler(String uri) {
//        RedirectServerAuthenticationSuccessHandler successHandler = new RedirectServerAuthenticationSuccessHandler();
//        successHandler.setLocation(URI.create(uri));
//        return successHandler;
//    }
//
//}